home *** CD-ROM | disk | FTP | other *** search
/ Practical Internet Web Designer 86 / PIWD86.iso / pc / contents / dreamweaver / software / dwmx2004.exe / Disk1 / data1.cab / Configuration_En / Commands / Design Notes.js < prev    next >
Encoding:
JavaScript  |  2003-09-05  |  13.3 KB  |  484 lines

  1. // Copyright 2000, 2001, 2002, 2003 Macromedia, Inc. All rights reserved.
  2.  
  3. //*************** GLOBALS  *****************
  4.  
  5. var helpDoc = MM.HELP_cmdDesignNotes;
  6.  
  7. var KEY_STATUS = "status";
  8. var KEY_NOTES  = "notes";
  9. var KEY_OPEN   = "showOnOpen";
  10. var PAIR_SEP   = " = ";
  11. var DEFAULT_STATUS = 0;
  12.  
  13. var T = ''; //TabControl object
  14. var DATA;
  15. var FILE_PTR = 0;
  16.  
  17. var FILE_IS_WRITEABLE;
  18.  
  19. //******************* API **********************
  20.  
  21. function commandButtons(){
  22.   var btns;
  23.  
  24.   //if launched but not writable, don't show OK button
  25.   if (MMNotes.FileInfo_isWriteable != null && MMNotes.FileInfo_isWriteable == false) {
  26.     btns = new Array(MM.BTN_Cancel, "cancelClicked()", MM.BTN_Help, "displayHelp()");
  27.   } else {
  28.     btns = new Array(MM.BTN_OK,     "okClicked()", MM.BTN_Cancel, "cancelClicked()", MM.BTN_Help, "displayHelp()");
  29.   }
  30.   return btns
  31. }
  32.  
  33. //***************** LOCAL FUNCTIONS  ******************
  34.  
  35. function initializeUI() {
  36.   var fullPath, fileName, filePath, origPathLen, result;
  37.  
  38.   //get selection and path
  39.   var fullPath = MMNotes.FileInfo_filePath; //grab global, set by launcher
  40.   if (fullPath) {
  41.     readMetafile(fullPath);
  42.     if (FILE_PTR) {
  43.       FILE_IS_WRITEABLE = true;
  44.       if (MMNotes.FileInfo_isWriteable != null && MMNotes.FileInfo_isWriteable == false) FILE_IS_WRITEABLE = false;
  45.       fileName = getFileName(fullPath);
  46.       filePath = getFilePathOnly(fullPath);
  47.       origPathLen = filePath.length;
  48.       while (filePath.length > 60){
  49.         filePath = filePath.substring(1);
  50.       }
  51.       if (origPathLen != filePath.length){
  52.         filePath = "..." + filePath;
  53.       }
  54.  
  55.       var tab0 = findObject("Tab0");
  56.       var tab1 = findObject("Tab1");
  57.  
  58.       //Use appropriate background & tabs for Mac OS X.
  59.       if (dw.isOSX()) {
  60.         findObject("tabBgWin").src = "../Shared/MM/Images/tabBgOSX435x334.gif";    
  61.         var oldMulti = RegExp.multiline;
  62.         RegExp.multiline = true;
  63.         var pat1 = /tabBg\.gif/;
  64.         tab0.innerHTML = tab0.innerHTML.replace(pat1, "tabBgOSX.gif");
  65.           tab1.innerHTML = tab1.innerHTML.replace(pat1, "tabBgOSX.gif");
  66.         var pat2 = /tabBgSel\.gif/;
  67.         tab0.innerHTML = tab0.innerHTML.replace(pat2, "tabBgSelOSX.gif");
  68.           tab1.innerHTML = tab1.innerHTML.replace(pat2, "tabBgSelOSX.gif");
  69.           RegExp.multiline = oldMulti;
  70.       // Use appropriate background & tabs for WinXP with themes  
  71.       } else if (dw.isXPThemed()) {    
  72.         findObject("tabBgWin").src = "../Shared/MM/Images/tabBgWinXP.gif";
  73.         var oldMulti = RegExp.multiline;
  74.         RegExp.multiline = true;
  75.         var pat1 = /tabBg\.gif/;
  76.         tab0.innerHTML = tab0.innerHTML.replace(pat1, "tabBgXP.gif");
  77.           tab1.innerHTML = tab1.innerHTML.replace(pat1, "tabBgXP.gif");
  78.         var pat2 = /tabBgSel\.gif/;
  79.         tab0.innerHTML = tab0.innerHTML.replace(pat2, "tabBgSelXP.gif");
  80.           tab1.innerHTML = tab1.innerHTML.replace(pat2, "tabBgSelXP.gif");
  81.           RegExp.multiline = oldMulti;
  82.       // Use standard background  
  83.       } else {    
  84.         findObject("tabBgWin").src = "../Shared/MM/Images/tabBgWin.gif";
  85.       }
  86.  
  87.       //Initialize the TabControl.  (Pass in the prefix used for the tab layers)
  88.       T = new TabControl('Tab');
  89.       //Add tab pages.   (Pass the layer name, and the page object)
  90.       T.addPage('mainLayer', new Pg1(LABEL_BasicInfo,fileName,filePath));
  91.       T.addPage('allLayer', new Pg2(LABEL_AllInfo,fileName,filePath));
  92.       //Initialize and display the tabs.  (Could pass the name of a page to start on)
  93.       T.start();
  94.     }
  95.   } else {
  96.     cancelClicked();
  97.   }
  98. }
  99.  
  100.  
  101.  
  102. function okClicked() {
  103.   T.finish();
  104.   if (FILE_PTR)
  105.       writeMetafile();
  106.   window.close();
  107.  
  108.   //update design notes columns in local file list in site window
  109.   if (MMNotes.UpdateSite == true)
  110.     site.refresh("local");
  111. }
  112.  
  113. function cancelClicked() {
  114.   if (FILE_PTR)
  115.       MMNotes.close(FILE_PTR);
  116.   window.close();
  117. }
  118.  
  119. function readMetafile(fullPath) {
  120.   var i, keys, temp;
  121.   FILE_PTR = MMNotes.open(fullPath); //open, or create metafile
  122.   if (FILE_PTR) {
  123.     DATA = new NameValuePair();
  124.     keys = MMNotes.getKeys(FILE_PTR); 
  125.     for (i=0; i<keys.length; i++) {
  126.       temp = MMNotes.get(FILE_PTR,keys[i]);
  127.       DATA.set(keys[i], temp);
  128.   } }
  129. }
  130.  
  131. function writeMetafile() {
  132.   var i, names, keys, dataToWrite=false;
  133.  
  134.   //remove old keys
  135.   keys = MMNotes.getKeys(FILE_PTR); 
  136.   for (i=0; i<keys.length; i++) {
  137.     if (DATA.get(keys[i])==null) MMNotes.remove(FILE_PTR,keys[i]); //if not in local list, remove
  138.   }
  139.   MMNotes.remove(FILE_PTR,KEY_STATUS); //clear out the old KEYS
  140.   MMNotes.remove(FILE_PTR,KEY_NOTES);
  141.   MMNotes.remove(FILE_PTR,KEY_OPEN);
  142.  
  143.   names = DATA.getNames();
  144.   for (i=0; i<names.length; i++)  {  //with each local, non-null key
  145.     MMNotes.set(FILE_PTR,names[i],DATA.get(names[i]));  //set it in the file
  146.   }
  147.  
  148.   MMNotes.close(FILE_PTR);
  149. }
  150.  
  151.  
  152. function getFileName(fullPath) {
  153.   var filePath = MMNotes.localURLToFilePath(fullPath);
  154.   var endPos = filePath.lastIndexOf("\\");
  155.   if (endPos == -1) endPos = filePath.lastIndexOf(":");
  156.   return filePath.substring(endPos+1);
  157. }
  158.  
  159.  
  160. function getFilePathOnly(fullPath) {
  161.   var filePath = MMNotes.localURLToFilePath(fullPath);
  162.   var endPos = filePath.lastIndexOf("\\");
  163.   if (endPos == -1) endPos = filePath.lastIndexOf(":");
  164.   return filePath.substring(0,endPos);
  165. }
  166.  
  167.  
  168. function makeValidKey(theStr) {
  169.   theStr = theStr.replace(/(\")/g,""); //disallow "
  170.   theStr = theStr.replace(/(\')/g,""); //disallow '
  171.   return theStr;
  172. }
  173.  
  174. function getSimpleDate() {
  175.   return createDateFromMask(DATE_Mask);
  176. }
  177.  
  178. //*************** Pg1 Class *****************
  179.  
  180. function Pg1(theTabLabel, theFileName, theFilePath) {
  181.   this.tabLabel    = theTabLabel;
  182.   this.fileName    = theFileName;
  183.   this.filePath    = theFilePath;
  184.  
  185.   this.listObj     = new ListControl("statusMenu");
  186.   this.notesObj    = findObject("notesField");
  187.   this.openObj     = findObject("openChbx");
  188. }
  189.  
  190.  
  191. //***** methods *****
  192.  
  193. Pg1.prototype.getTabLabel = Pg1_getTabLabel; //required
  194. Pg1.prototype.canLoad = Pg1_canLoad;
  195. Pg1.prototype.load = Pg1_load;
  196. Pg1.prototype.update = Pg1_update;
  197. Pg1.prototype.unload = Pg1_unload;
  198. Pg1.prototype.drawFilename = Pg1_drawFilename;
  199. Pg1.prototype.drawFilepath = Pg1_drawFilepath;
  200.  
  201.  
  202. function Pg1_getTabLabel() {
  203.   return this.tabLabel;
  204. }
  205.  
  206.  
  207. //Called to check if a page can be loaded
  208. //
  209. function Pg1_canLoad() {
  210.   this.drawFilename();
  211.   this.drawFilepath();
  212.   return true;
  213. }
  214.  
  215.  
  216. //Called when the layer for this page is displayed.
  217. // Use this call to initialize controls.
  218.  
  219. function Pg1_load() {
  220.   var i;
  221.  
  222.   with (this) {
  223.     listObj.setAll(STATUS_ITEMS); //load select menu
  224.  
  225.     //get status
  226.     temp = stripSpaces(DATA.get(KEY_STATUS));
  227.     if (!temp) listObj.setIndex(DEFAULT_STATUS);
  228.     else {
  229.       for (i=0; i<listObj.getLen(); i++) { //look for status in menu
  230.         if (listObj.get(i) == temp) {
  231.           listObj.setIndex(i);
  232.           break;
  233.       } }
  234.       if (i == listObj.getLen()) listObj.append(temp); //if nonexistent, add it
  235.     }
  236.  
  237.     //get notes
  238.     temp = DATA.get(KEY_NOTES);
  239.     notesObj.value = temp || "";
  240.  
  241.     //get open flag
  242.     temp = DATA.get(KEY_OPEN);
  243.     if (temp != null) openObj.checked = (temp.toString().toLowerCase() == "true");
  244.   }
  245. }
  246.  
  247.  
  248. //Called when another page is about to be shown, or finish() is called on
  249. // the tabControl.  Use this call to perform any finishing tasks.
  250.  
  251. function Pg1_unload() {
  252.   return true;
  253. }
  254.  
  255.  
  256. //Called when one of the page controls calls the tabControl update function.
  257. // Use this call to respond to user input.
  258. function Pg1_update(theItemName) {
  259.  
  260.   if (FILE_PTR && FILE_IS_WRITEABLE) with (this) {
  261.       if (theItemName == "insertDate") {
  262.         var theDate = getSimpleDate() + ": \n";
  263.         notesObj.value = theDate + notesObj.value;
  264.         DATA.set(KEY_NOTES,notesObj.value || null); //save notes
  265.  
  266.       } else if (theItemName == "statusMenu") {
  267.         DATA.set(KEY_STATUS,listObj.get() || null); //save status
  268.  
  269.       } else if (theItemName == "notesField") {
  270.         DATA.set(KEY_NOTES,notesObj.value || null); //save notes
  271.  
  272.       } else if (theItemName == "openChbx") {
  273.         DATA.set(KEY_OPEN,openObj.checked || null); //save open flag
  274.     }
  275.  
  276.   } else {
  277.     alert(MSG_ReadOnlyFile);
  278.   }
  279. }
  280.  
  281. function Pg1_drawFilename() {
  282.   var fNameObj = findObject("fileName1");
  283.   if (fNameObj) {
  284.     fNameObj.innerHTML = this.fileName;
  285.   }
  286. }
  287.  
  288.  
  289. function Pg1_drawFilepath() {
  290.   var fPathObj = findObject("filePath1");
  291.   if (fPathObj) {
  292.     fPathObj.innerHTML = this.filePath;
  293.   }
  294. }
  295.  
  296.  
  297.  
  298. //***************** Pg2 Class ******************
  299.  
  300. function Pg2(theTabLabel, theFileName, theFilePath) {
  301.   this.tabLabel    = theTabLabel;
  302.   this.fileName    = theFileName;
  303.   this.filePath    = theFilePath;
  304.  
  305.   this.listObj     = new ListControl("allItems");
  306.   this.nameObj     = findObject("itemName")
  307.   this.valueObj    = findObject("itemValue")
  308.   this.keys        = new Array();
  309. }
  310.  
  311.  
  312. //***** methods *****
  313.  
  314. Pg2.prototype.getTabLabel = Pg2_getTabLabel;
  315. Pg2.prototype.canLoad = Pg2_canLoad;
  316. Pg2.prototype.load = Pg2_load;
  317. Pg2.prototype.update = Pg2_update;
  318. Pg2.prototype.unload = Pg2_unload;
  319. Pg2.prototype.drawList = Pg2_drawList;
  320. Pg2.prototype.drawSelection = Pg2_drawSelection;
  321. Pg2.prototype.drawFilename = Pg2_drawFilename;
  322. Pg2.prototype.drawFilepath = Pg2_drawFilepath;
  323.  
  324.  
  325.  
  326. function Pg2_getTabLabel() {
  327.   return this.tabLabel;
  328. }
  329.  
  330.  
  331.  
  332. //Called to check if a page can be loaded
  333. //
  334. function Pg2_canLoad() {
  335.   this.drawFilename();
  336.   this.drawFilepath();
  337.   return true;
  338. }
  339.  
  340.  
  341.  
  342. //Called when the layer for this page is displayed.
  343. // Use this call to initialize controls.
  344. //
  345. function Pg2_load() {
  346.   with (this) {
  347.     drawList();
  348.     listObj.setIndex(0); //select first item
  349.     drawSelection()
  350.   }
  351. }
  352.  
  353.  
  354.  
  355. //Called when another page is about to be shown, or finish() is called on
  356. // the tabControl.  Use this call to perform any finishing tasks.
  357. function Pg2_unload() {
  358.   return true;
  359. }
  360.  
  361.  
  362.  
  363. //Called when one of the page controls calls the tabControl update function.
  364. // Use this call to respond to user input.
  365. function Pg2_update(theItemName) {
  366.   var i, temp, temp2;
  367.  
  368.   if (theItemName == "allItems") with (this) {
  369.     drawSelection();
  370.  
  371.   } else if (FILE_IS_WRITEABLE) {
  372.  
  373.     if (theItemName == "addItem") with (this) {
  374.       listObj.append();
  375.       valueObj.value = "";
  376.       nameObj.value  = "";
  377.       nameObj.focus();
  378.       nameObj.select();
  379.   
  380.     } else if (theItemName == "delItem") with (this) {
  381.       DATA.del(listObj.getIndex());
  382.       listObj.del();
  383.       drawSelection();
  384.   
  385.     } else if (theItemName == "itemName" || theItemName == "itemValue") with (this) {
  386.       temp = nameObj.value;
  387.       temp2 = (valueObj.value);
  388.       if (temp) { //if valid name
  389.         temp = stripSpaces(makeValidKey(temp));
  390.         if (temp) { //if valid name
  391.           if (listObj.get()) { //if selection is not blank (not new item)
  392.             var oldName = DATA.getName(listObj.getIndex()); //get prior name
  393.             if (temp != oldName) DATA.changeName(oldName,temp); //if name changed, update it
  394.           }
  395.           DATA.set(temp,temp2);
  396.           drawList();
  397.         } else {
  398.           alert(MSG_InvalidName);
  399.     } } }
  400.  
  401.   } else { //file is not writable
  402.     alert(MSG_ReadOnlyFile);
  403.   }
  404. }
  405.  
  406.  
  407. //Called when the layer for this page is displayed.
  408. // Use this call to initialize controls.
  409. //
  410. function Pg2_drawList() {
  411.   var i, allItems;
  412.  
  413.   with (this) {
  414.     listObj.setAll(DATA.getAll());       //clear out the old list
  415.     if (listObj.getLen() > 0) {
  416.       drawSelection();                      //display stuff in fields
  417.     }
  418.   }
  419. }
  420.  
  421.  
  422. function Pg2_drawSelection() {
  423.   var name, value;
  424.  
  425.   with (this) {
  426.     name = DATA.getName(listObj.getIndex()); //get the name for the current selection
  427.     name = name || ""; //make blank if null
  428.     nameObj.value = name;
  429.     value = DATA.get(name);
  430.     value = value || ""; //make blank if null
  431.     valueObj.value = value;
  432.   }
  433. }
  434.  
  435.  
  436. function Pg2_drawFilename() {
  437.   var fNameObj = findObject("fileName2");
  438.   if (fNameObj) {
  439.     fNameObj.innerHTML = this.fileName;
  440.   }
  441. }
  442.  
  443.  
  444. function Pg2_drawFilepath() {
  445.   var fPathObj = findObject("filePath2");
  446.   if (fPathObj) {
  447.     fPathObj.innerHTML = this.filePath;
  448.   }
  449. }
  450.  
  451. //***************** End of Pg2 Class ******************
  452.  
  453. //***************** Generic Functions *****************
  454.  
  455.  
  456. //Renders date (numbers only) as needed. Accepts the following tokens:
  457. //M or MM, D or DD, YY or YYYY. MM means pad with zero. Tokens can be mixed with any punctuation.
  458. //Examples: M/D/YY => 6/25/99  or  YYYY.MM.DD => 1999.06.25
  459.  
  460. //This is only temporarily in the localized code. Should be moved
  461. //to Shared/MM/Scripts/CMN/dateID.js for the next release.
  462.  
  463. function createDateFromMask(dateStr) {
  464.   var today = new Date();
  465.   var theYear  = String(today.getFullYear());
  466.   var theMonth = String(Number(today.getMonth())+1);
  467.   var theDate  = String(today.getDate());
  468.  
  469.  
  470.   //Replace Year
  471.   dateStr = dateStr.replace(/YYYY/g,theYear);
  472.   dateStr = dateStr.replace(/YY/g,theYear.substring(2));
  473.  
  474.   //Replace Month
  475.   dateStr = dateStr.replace(/MM/g,((Number(theMonth)<10)?"0":"")+theMonth);
  476.   dateStr = dateStr.replace(/M/g,theMonth);
  477.  
  478.   //Replace Date
  479.   dateStr = dateStr.replace(/DD/g,((Number(theDate)<10)?"0":"")+theDate);
  480.   dateStr = dateStr.replace(/D/g,theDate);
  481.  
  482.   return dateStr;
  483. }
  484.